<!--  -->
<template>
  <el-container class="home_container">
    <el-header style="text-align: center; line-height: 60px">
      欢迎来到主页！
      <el-button @click="handleQuit()" style="float: right">退出</el-button>
    </el-header>
    <el-container>
      <el-aside width="220px">
        <h5>结构</h5>
        <el-menu
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
        >
          <el-menu-item
            :index="(item.id) + ''"
            v-for="item in noChildren"
            :key="item.id"
            @click="handleClickMenu(item)"
          >
            <i class="el-icon-location"></i>
            <span>{{ item.name }}</span>
          </el-menu-item>
          <el-submenu :index="(item.id) + ''" v-for="item in children" :key="item.id">
            <!-- 控制状态栏的开启和关闭 -->
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ item.name }}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item :index="(subItem.id)+''" v-for="subItem in item.children" :key="subItem.id" @click="handleClickMenu(subItem)">{{subItem.name}}</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-main>
        <!-- <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane
            :label="item.name"
            v-for="item in label"
            :key="item.id"
            >{{ item.name }}</el-tab-pane
          >
        </el-tabs> -->
        <router-view/>
      </el-main>
    </el-container>

  </el-container>
</template>

<script>
export default {
  data() {
    return {
      count: 0,
      label: [
        {
          id: 1,
          name: "教学管理",
          path: "/page1",
        },
        {
          id: 2,
          name: "虚拟模式",
          path: "/page2",
        },
        {
          id: 3,
          name: "我的漫游",
          path: "/page3",
        },
        {
          id: 4,
          name:"虚无空间",
          children: [
            {
              id: 4.1,
              name: "page4",
              path: "/page4",
            },
            {
              id: 4.2,
              name: "page5",
              path: "/page5",
            },
          ],
        },
      ],
    };
  },

  computed: {
    noChildren() {
      return this.label.filter((item) => {
        return !item.children;
      });
    },
    children() {
      return this.label.filter((item) => {
        return item.children;
      });
    },
  },

  components: {},

  methods: {
    handleQuit() {
      window.sessionStorage.clear();
      this.$router.push("/login");
      window.alert("退出成功！");
    },
    handleOpen(index) {
      console.log(index);
    },
    handleClose(index) {
      console.log(index);
    },
    handleClick(e) {
      console.log("点击了：");
      console.log(e);
    },
    handleClickMenu(item){
        this.$router.push({
            path: item.path
        })
    }
  },
};
</script>
<style scoped>
.home_container {
  height: 100%;
}
.el-header {
  background-color: red;
}
.el-aside {
}
</style>